<?php
/**
* @property CI_Loader $load
* @property CI_Form_validation $form_validation
* @property CI_Input $input
* @property CI_Email $email
* @property CI_DB_active_record $db
*
*/
class Stat extends CI_Model
{
    function get_stat($code)
    {
        $query=$this->db->query("SELECT
                                newstat.`year`,
                                newstat.`month`,
                                newstat.received,
                                newstat.rejected,
                                newstat.completed
                                FROM
                                newstat
                                WHERE
                                newstat.code =  '$code'
                                ORDER BY
                                newstat.`year` DESC,
                                newstat.`month` DESC");
        return $query->row_array();
    }
    function get_stat2($year,$month,$code)
    {
        $this->db->select("received,rejected,completed");
        $this->db->where('year', $year) ;  
        $this->db->where('month', $month) ;   
        $this->db->where('code', $code); 
        $query=$this->db->get('newstat');
        return $query->row_array();
    }
    function get_year()
    {
         $query=$this->db->query("SELECT distinct
        newstat.`year`
        FROM
        newstat
        ORDER BY
        newstat.`year` DESC");
        return $query->result();
    }
    function get_max_month($year)
    {
        $this->db->select_max('month');
        $this->db->where('year',$year);
        $query=$this->db->get('newstat');
        $row= $query->row();
        return $row->month;
    }
}